/**
 * Created by 李一方 on 2015/3/6.
 */

var allImage = [];
var selected = 4, speed = 0;
var isMoving = false;
var continueMove = true;

function slide() {
    if (continueMove == false) {
        stopAt(selected);
        return;
    }

    var newSelected = selected - speed;

    if (newSelected < 0) {
        newSelected = 0;
        continueMove = false;
    } else if (newSelected > 49) {
        newSelected = 49;
        continueMove = false;
    }

    if (selected == newSelected) {
        stopAt(selected);
        return;
    }

    isMoving = true;
    var a = dojo.fx.slideTo({
        node: "images", duration: 500, top: 0, left: (4 - newSelected) * 65, easing: dojo.fx.easing.linear
    });
    selected = newSelected;
    dojo.connect(a, "onEnd", slide);
    a.paly();
}

function serSpeed(e) {
    speed = Math.round((e.clientX - 290) / 100);
    if (speed !== 0) {
        if (isMoving === false) {
            continueMove = true;
            slide();
        }
    }
}

function stopAt(selected) {
    isMoving = false;
    document.getElementById("selectedDisplay").innerHTML = "<img src=\"" + allImage[selected].src + "\"/>";

}
